package com.ruoyi.project.dict.shuowenpage.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.shuowenpage.domain.ShuowenPage;
import com.ruoyi.project.dict.shuowenpage.service.IShuowenPageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说文解字Controller
 *
 * @author shixiangwen
 * @date 2022-05-27
 */
@Controller
@RequestMapping("/dict/shuowenpage")
public class ShuowenPageController extends BaseController {
    private String prefix = "dict/shuowenpage";

    @Autowired
    private IShuowenPageService shuowenPageService;

    @RequiresPermissions("dict:shuowenpage:view")
    @GetMapping()
    public String shuowenpage() {
        return prefix + "/shuowenpage";
    }

    /**
     * 查询说文解字列表
     */
    @RequiresPermissions("dict:shuowenpage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShuowenPage shuowenPage) {
        startPage();
        List<ShuowenPage> list = shuowenPageService.selectShuowenPageList(shuowenPage);
        return getDataTable(list);
    }

    /**
     * 导出说文解字列表
     */
    @RequiresPermissions("dict:shuowenpage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShuowenPage shuowenPage) {
        List<ShuowenPage> list = shuowenPageService.selectShuowenPageList(shuowenPage);
        ExcelUtil<ShuowenPage> util = new ExcelUtil<ShuowenPage>(ShuowenPage.class);
        return util.exportExcel(list, "shuowenpage");
    }

    /**
     * 新增说文解字
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存说文解字
     */
    @RequiresPermissions("dict:shuowenpage:add")
    @Log(title = "说文解字", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShuowenPage shuowenPage) {
        return toAjax(shuowenPageService.insertShuowenPage(shuowenPage));
    }

    /**
     * 修改说文解字
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ShuowenPage shuowenPage = shuowenPageService.selectShuowenPageById(id);
        mmap.put("shuowenPage", shuowenPage);
        return prefix + "/edit";
    }

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        ShuowenPage shuowenPage = shuowenPageService.selectShuowenPageById(id);
        mmap.put("shuowenPage", shuowenPage);
        return prefix + "/detail";
    }

    /**
     * 修改保存说文解字
     */
    @RequiresPermissions("dict:shuowenpage:edit")
    @Log(title = "说文解字", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShuowenPage shuowenPage) {
        return toAjax(shuowenPageService.updateShuowenPage(shuowenPage));
    }

    /**
     * 删除说文解字
     */
    @RequiresPermissions("dict:shuowenpage:remove")
    @Log(title = "说文解字", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(shuowenPageService.deleteShuowenPageByIds(ids));
    }
}
